<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*防抖*/ 
        function debounce(fn,delay){
            let timer = null
            return function(...args){
                if(timer){
                    clearTimeout(timer)
                }
                timer = setTimeout(()=>{
                    fn.apply(this,args)
                },delay)
            }
        }

        function debounce(fn,delay){
            let timer = null
            return function(...args){
                if(timer){
                    clearTimeout(timer)
                }
                timer = setTimeout(()=>{
                    fn.apply(this,args)
                },delay)
            }
        }

        function throttle(fn,delay){
            let timer = 0
            return function(...args){
                if(!timer){
                    timer = setTimeout(()=>{
                        fn.apply(this,args)
                        timer = null
                    },delay)
                }
            }
        }

        /*节流*/
        function throttle(fn,delay){
            let timerId = 0
            return function(...args){
                if(!timerId){
                    timerId = setTimeout(()=>{
                        fn.apply(this,args);
                        timer = null
                    },delay)
                }
            }
        }
    </script>
</body>
</html>